package com.api.gbhg.liuwenbo.version3.api;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.liuwenbo.version2.api.BudgetSectionIncomeApi2;
import com.api.gbhg.liuwenbo.version2.api.CauseApi;
import com.api.gbhg.liuwenbo.version2.api.FinancialAppropriationApi;
import com.api.gbhg.liuwenbo.version2.pojo.BudgetSectionIncome2;
import com.api.gbhg.liuwenbo.version3.util.ApiUtil;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 财政拨款1
 * @Version  3.0
 * @Author lwb
 * @Date
 */
@Path("v3/FinancialAppropriation")
public class FinancialAppropriationApi3 {

    private BudgetSectionIncomeApi2 api = new FinancialAppropriationApi();

    @POST
    @Path("/getFinancialAppropriationList")
    @Produces(MediaType.APPLICATION_JSON)
    public String getFinancialAppropriationList(Map param){
        Map msgMap = new HashMap();
        //System.err.println(param);
        //type 为预留参数 防止后面要单独显示除去缉私局的
        if (param == null ||!param.containsKey("nf") ||!param.containsKey("jz") ||!param.containsKey("type")){
            msgMap.put("code","500");
            msgMap.put("msg","缺少参数 请检查参数是否完整！");
            msgMap.put("data","");
            return JSON.toJSONString(msgMap);
        }

        Map<String, Object> paramFormat = api.paramFormat(param);

        List<BudgetSectionIncome2> czbksyData = null;//所有除缉私局
        List<BudgetSectionIncome2> czbkjsjData = null;//缉私局数据

        try {
            paramFormat.put("type",0);
            czbksyData = CauseApi.AdjustDataStructure(new ArrayList<>(),api.getCzbksrData(paramFormat));
            paramFormat.put("type",1);
            czbkjsjData = CauseApi.AdjustDataStructure(new ArrayList<>(),api.getCzbksrData(paramFormat));

            Map<String,Object> map = new HashMap<>();
            map.put("非海关合计", ApiUtil.structureConversion(czbksyData,paramFormat.get("nf").toString()));
            map.put("海关合计",ApiUtil.structureConversion(czbkjsjData,paramFormat.get("nf").toString()));
            msgMap.put("code","200");
            msgMap.put("msg","");
            msgMap.put("data",map);

        }catch (Exception e){
            e.printStackTrace();
            msgMap.put("code","500");
            msgMap.put("msg","程序异常，请联系管理员！"+e.getMessage());
            msgMap.put("data","");
            return JSON.toJSONString(msgMap);
        }
        return JSON.toJSONString(msgMap);
    }
}
